import random

#用户：账号、账户类型、姓名、密码、地址、存款余额、开户行
user = {
    "account":"",
    "account_type":0,
    "name":"",
    "password":000000,
    "address":[],
    "balance":0,
    "opening_bank":""
}
#地址：国家、省份、街道、门牌号
address = ["", "", "", ""]
#银行：存储100用户的库、本银行名称
bank = ["中国农业银行", {
    1:{"account":"69523587", "account_type":0, "name":"Alice", "password":000000,
       "address":["河南", "郑州","中原","863软件园"], "balance":50000, "opening_bank":"中原分行"},
    2:{"account":"69733587", "account_type":1, "name":"Bob", "password":111111,
       "address":["陕西", "西安","未央","赛格"], "balance":0, "opening_bank":"未央分行"}
}]


#开户
def open_account(bank_form, account_type_form, name_form, password_form, address_form, balance_form, opening_bank_form):
    mark = 0  # 用于记录开户结果，1表示成功，2表示用户已存在，3表示用户库已满
    i = 0
    account_form = str(random.randint(10000000, 99999999))
    for item in bank_form.values():
        i += 1
        if item["account"] == account_form:
            print("账户已存在！")
            mark = 2
            break
    if mark != 2 and i > 99:
        print("用户库已满！")
        mark = 3
    elif mark != 2 and mark != 3:
        i += 1
        bank_form[i] = {}
        bank_form[i]["account"] = account_form
        bank_form[i]["account_type"] = account_type_form
        bank_form[i]["name"] = name_form
        bank_form[i]["password"] = password_form
        bank_form[i]["address"] = address_form
        bank_form[i]["balance"] = balance_form
        bank_form[i]["opening_bank"] = opening_bank_form
        print("开户成功")
    return bank_form, mark

#存钱
def save_money(account_form, money_form, bank_form):
    mark = 0
    for item in bank_form.values():
        if item["account"] == account_form:
            item["balance"] += money_form
            mark = 1
    if mark == 0:
        print("账户不存在！")
        return False
    return bank_form

#取钱
def draw_money(account_form, password_form, money_form, bank_form):
    mark = 0
    for item in bank_form.values():
        if item["account"] == account_form:
            if password_form == item["password"]:
                if item["balance"] >= money_form:
                    item["balance"] -= money_form
                    print("取款成功！")
                    mark = 1
                else:
                    print("余额不足！")
                    return 3
            else:
                print("密码错误！")
                return 2
    if mark == 0:
        print("没有该账户！")
        return 1
    return bank_form

#转账
def transfer_account(account_form_1, account_form_2, password_form, money_form, bank_form):
    mark = 0
    aci = 0
    for item in bank_form.values():
        if item["account"] == account_form_1:
            aci += 1
            if password_form == item["password"]:
                if item["balance"] >= money_form:
                    item["balance"] -= money_form
                    mark += 1
                else:
                    print("余额不足!")
                    return 3
            else:
                print("密码错误！")
                return 2
        if item["account"] == account_form_2:
            aci += 1
            item["balance"] += money_form
            mark += 1
    if mark == 2:
        print("转账成功!")
    if aci != 2:
        print("账户错误！")
        return 1
    return bank_form

#查询账户
def search_account(account_form, password_form, bank_form):
    mark = 0
    for item in bank_form.values():
        if item["account"] == account_form:
            mark = 1
            if password_form == item["password"]:
                print(item)
            else:
                print("密码错误！")
    if mark == 0:
        print("账户不存在")

i = 1
while i:
    print("******************************")
    print("*   中国农业银行账户管理系统   *")
    print("******************************")
    print("*            选项            *")
    print("*           1.开户           *")
    print("*           2.存钱           *")
    print("*           3.取钱           *")
    print("*           4.转账           *")
    print("*           5.查询           *")
    print("*           6.退出           *")
    print("******************************")
    choice = int(input("请输入要进行的业务标号："))
    if choice == 1:
        open_account_list = open_account(bank[1], 1, "cherry", 98765432, ["河南", "商丘", "虞城", "刘集"], 9698700,
                                         "虞城分行")
        bank[1] = open_account_list[0]
        print(bank)
    elif choice == 2:
        bank[1] = save_money("69523587", 90000, bank[1])
        print(bank)
    elif choice == 3:
        bank[1] = draw_money("69523587", 000000, 5000, bank[1])  # python不允许首位为0
        print(bank[1])
    elif choice == 4:
        bank[1] = transfer_account("69523587", "69733587", 000000, 10000, bank[1])
        print(bank)
    elif choice == 5:
        search_account("69523587", 000000, bank[1])
    elif choice == 6:
        i = 0













































